package Demo;

import java.io.*;

public class Test1 {
    //以字节流写数据和以字节流读数据
    public static void main(String[] args) {
        OutputStream io=null;
        try{
            io=new FileOutputStream("C:\\java2024\\20241126\\test1.txt");
            io.write("你好，java".getBytes());
        }catch (IOException e) {
            e.printStackTrace();
        }finally {
            if(io!=null){
                try{
                    io.close();
                }catch (IOException e){
                    e.printStackTrace();
                }
            }
        }
        InputStream is=null;
        try{
            is=new FileInputStream("C:\\java2024\\20241126\\test1.txt");
            byte[] b=new byte[1024];
            int len;
            while((len=is.read(b))!=-1){
                System.out.println(new String(b,0,len));
            }
        }catch (IOException e){
            e.printStackTrace();
        }finally {
            if(is!=null){
                try {
                    is.close();
                }catch (IOException e){
                    e.printStackTrace();
                }
            }
        }
    }
}
